﻿Namespace DoFactory.GangOfFour.Bridge.Structural
    ''' <summary>
    ''' MainApp startup class for Structural
    ''' Bridge Design Pattern.
    ''' </summary>
    Public Class MainApp

        ''' <summary>
        ''' Entry point into console application.
        ''' </summary>
        Public Shared Sub Main()

            Dim ab As Abstraction = New RefinedAbstraction()
            ' Set implementation and call
            ab.Implementor = New ConcreteImplementorA()
            ab.Operation()

            ' Change implemention and call
            ab.Implementor = New ConcreteImplementorB()
            ab.Operation()

        End Sub

    End Class

    ''' <summary>
    ''' The 'Abstraction' class
    ''' </summary>
    Class Abstraction
        Protected m_implementor As Implementor

        ' Property
        Public WriteOnly Property Implementor() As Implementor
            Set(ByVal value As Implementor)
                m_implementor = value
            End Set
        End Property

        Public Overridable Sub Operation()
            m_implementor.Operation()
        End Sub

    End Class

    ''' <summary>
    ''' The 'Implementor' abstract class
    ''' </summary>
    MustInherit Class Implementor
        Public MustOverride Sub Operation()
    End Class

    ''' <summary>
    ''' The 'RefinedAbstraction' class
    ''' </summary>
    Class RefinedAbstraction
        Inherits Abstraction

        Public Overrides Sub Operation()
            MyBase.m_implementor.Operation()
        End Sub

    End Class

    ''' <summary>
    ''' The 'ConcreteImplementorA' class
    ''' </summary>

    Class ConcreteImplementorA
        Inherits Implementor

        Public Overrides Sub Operation()
            Console.WriteLine("ConcreteImplementorA Operation")
        End Sub
    End Class

    ''' <summary>
    ''' The 'ConcreteImplementorB' class
    ''' </summary>
    Class ConcreteImplementorB
        Inherits Implementor

        Public Overrides Sub Operation()
            Console.WriteLine("ConcreteImplementorB Operation")
        End Sub

    End Class

End Namespace
